var timer;//轮播定时器
var t;//header定时器
//导航背景颜色改变
function changeActive(target) {
	$('.active').removeClass('active');
	//当前点击的li加上class
	target.addClass("active");
}

//头部搜索效果
function changeHead() {
	//alert(scrollTop)
	$(window).scroll(function() {
		var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
		if(180>scrollTop > 0) {
			$(".check_head").css({
				/*"width": "100%",
				"margin": "0",
				"height": "45px",
				"background": "#28d2d7",
				"border": "solid 1px #CCCCCC",
				"line-height": "40px",
				"border-radius":"0"*/
				"opacity": scrollTop/180,
				
			})
		}else {
			$(".check_head").css({
				/*"text-align": "center",
				"height": "40px",
				"background": "rgba(250, 250, 250, 0)",
				"z-index": "1000",
				"border": "solid 0",
				"width": "100%",*/
				"opacity": "1",
			})
		}
	})

}

//头部时间监听
function headerListenning(){
//	var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
	$("#check_head").bind("scroll",changeHead())
}
//canvas coupan
/*function coupanCanvas(){
	
	var coupCanvas=document.getElementById("coupanCanvas").getContext("2d");
	coupCanvas.fillStyle="#F0F0F0";
	coupCanvas.strokeStyle="#666666";
	coupCanvas.lineWidth=0.5;
	coupCanvas.setLineDash([1,5]);
	coupCanvas.beginPath();
	coupCanvas.moveTo(225,0)
	coupCanvas.lineTo(225,150);
	coupCanvas.stroke();
	coupCanvas.beginPath();
	coupCanvas.arc(225,0,5,0,Math.PI)
	coupCanvas.fill();
	coupCanvas.beginPath();
	coupCanvas.arc(225,150,5,Math.PI,2*Math.PI)
	coupCanvas.fill();
	
}*/
$(document).ready(function() {

	/*	$(window).scroll(0,function(){
			$("#check_head").css({
				"width":"66.7%",
				"margin-left":"15%",
				"height":"21px",
				"background":"rgba(250, 250, 250, 0.5)",
				"z-index":"99",
				"text-align":"center"
			})
		})*/

	if(t) {
		t = clearInterval()
	}
//	t = setInterval("changeHead()", 10)
	headerListenning()
	//导航切换开始
	$("#discount").hide();
	$("#promotions").hide();
	$("#integral").hide();
	$("#target_discount").click(function() {
		$("#discount").show();
		$("#recommend").hide();
		$("#promotions").hide();
		$("#integral").hide();
		changeActive($(this));
	});
	$("#target_promotions").click(function() {
		$("#promotions").show();
		$("#recommend").hide();
		$("#discount").hide()
		$("#integral").hide();
		changeActive($(this));
        $.ajax({
            type:'get',
            url:'/fanZone/buyer/coupon/allCoupon',
            dataType:'json',
            success:function(result){
                //console.info(result);
                $("#promotions").append(result);
            }
        });
	});
	$("#target_recommend").click(function() {
		$("#promotions").hide();
		$("#recommend").show();
		$("#discount").hide();
		$("#integral").hide();
		changeActive($(this));
	});
	$("#target_integral").click(function() {
		$("#promotions").hide();
		$("#recommend").hide();
		$("#discount").hide();
		$("#integral").show();
		changeActive($(this));
	});
	//导航切换结束，幻灯片开始
	$(".slider").hover(function() {
		$("#btn_prev,#btn_next").fadeIn()
	}, function() {
		$("#btn_prev,#btn_next").fadeOut()
	});

   // $("#findBussiness #target_recommend span").trigger("click");
    $dragBln = false;

	$(".slider_img").touchSlider({
		flexible: true,
		speed: 200,
		btn_prev: $("#btn_prev"),
		btn_next: $("#btn_next"),
		paging: $(".slider_point a"),
		counter: function(e) {
			$(".slider_point a").removeClass("on").eq(e.current - 1).addClass("on"); //图片顺序点切换
			$(".img_font span").hide().eq(e.current - 1).show(); //图片文字切换
		}
	});

	$(".slider_img").bind("mousedown", function() {
		$dragBln = false;
	});

	$(".slider_img").bind("dragstart", function() {
		$dragBln = true;
	});

	$(".slider_img a").click(function() {
		if($dragBln) {
			return false;
		}
	});

	timer = setInterval(function() {
		$("#btn_next").click();
	}, 5000);

	$(".img_gallery").hover(function() {
		clearInterval(timer);
	}, function() {
		timer = setInterval(function() {
			$("#btn_next").click();
		}, 5000);
	});

	$(".slider_img").bind("touchstart", function() {
		clearInterval(timer);
	}).bind("touchend", function() {
		timer = setInterval(function() {
			$("#btn_next").click();
		}, 5000);
	});
	//回到顶部
	$("#toTop").click(function() {
		var sc = $(window).scrollTop();
		$('body,html').animate({
			scrollTop: 0
		}, 500);
	})
	
	
	//模态框
	
	$(".h").click(function(){
		$(".bg-model").css("display","none");
		$("body").css({
			"overflow": "auto"
		});
	})
	$(".bg-model>*").not(".content").click(function(){
		$(".bg-model").css("display","none")
		$("body").css({
			"overflow": "auto"
		});
	})

	
	//ajax测试
	
	
	//模态框测试
	//	$("#rec_img").click(function(){
	//		modal("img/01.jpg")
	//	})
	//	
/*	$("#rec_img").click(function() {　　
		$(".model").fadeTo(300, 1)　　 //隐藏窗体的滚动条
		　　 $("body").css({
			"overflow": "hidden"
		});
	});
	$(".h").click(function() {
		$(".model").css("display", "none")
	})
	$(".bg-model>*").not(".content").click(function() {
		$(".model").css("display", "none")
	})*/
//	coupanCanvas()


    $("#target_recommend").trigger("click");
});
function recommend() {
     $("#target_recommend").click(function() {
        alert("点击事件");
     });
}
function modelclick(){
	
		$(".bg-model").fadeTo(300, 1)　　 //隐藏窗体的滚动条
			$("body").css({
			"overflow": "hidden"
		});

}
function modal(param) {
	alert("ss")
	var modalDiv = "<div class='model'></div>"

	var modalChild = "<div class='modalChild'></div>";
	$("body").prepend(modalDiv);
	$("body").css({
		"overflow": "hidden"
	});
	$('.model').css({
		"width": "100%",
		"height": "100%",
		"margin": "auto",
		"background": "#CCCCCC",
		"z-index": "9999",
		"display": "block",
		"position": "fixed"
	})
	$(".model").append(modalChild);

	$('.modalChild').css({
		"width": "80%",
		"height": "60%",
		"margin": "auto",
		"margin-top": "20%",
		"background": "red",
		"z-index": "9999"
	})
	var img = "<img />"
	$(".modalChild").append(img);
	$(".modalChild img").attr("src", param);
	$(".modalChild img").css({
		"width": "100%",
		"height": "100%"
	})
	//	alert(modalDiv)
	var modelc = "<div id='wh100'></div>";
	$(".model").append(modelc);
	$("#wh100").css({
		"width": "100px",
		"height": "100px",
		"background": "red"
	})
	
}
